/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * Using JQuery to do AJAX
 */



var ajax = {
    
    get: function(url, dataType, todo) { 
        $.ajax({
            
            type: "GET",
            url: url,
            dataType:dataType === undefined || dataType == null? "html":dataType,
           
            success: function(result) {
                if(todo !== undefined && typeof todo === "function")
                    todo.call(this, result);
            },
            error: function(xhr, textStatus, errorThrown) {
                alert('An error occurred! ' + ( errorThrown ? errorThrown :
                    xhr.status + textStatus));
            }
        })
    },

    post: function(url, data, dataType,todo){
        $.ajax({
            type: "POST",
            url: url,
            data: data,
            dataType: dataType === undefined || dataType == null? "text":dataType,
            complete: function(result){              
                if(todo !== undefined && typeof todo === "function")
                    todo.call(this, result);
            }
        })
    }
}


